package com.sumainfor.pc.market.controller;

import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.PageUtils;
import com.sumainfor.common.utlis.Pager;
import com.sumainfor.pc.market.feign.Zfeign.ZwxTenantFeign;
import com.sumainfor.pc.market.service.gmio.PactGmioService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author Meng
 * @ClassName TemPorHouController
 * @date 2020/1/3 21:19
 * @description: TODO
 */
@Controller
@RequestMapping("/TemPorHou")
public class TemPorHouController {
    @Autowired
    PactGmioService pactGmioService;

    @Autowired
    ZwxTenantFeign zwxTenantFeign;

    /**
     * 发送临时账单的房源列表
     * @param params
     * @param pager
     * @return
     */
    @PostMapping("/getTenHousList")
    @ResponseBody
    public JsonResult getTenHousList(@RequestBody Map<String,Object> params, Pager pager){

        if (!params.get("TenPhone").toString().equals("")&&params.get("TenPhone").toString()!=null){
            JsonResult tenresult = zwxTenantFeign.getTenId(params);
            Map<String,Object> tenMap = (Map<String, Object>) tenresult.get("result");
            if (tenMap !=null){
                params.put("TenId",tenMap.get("TenId"));
            }
        }
        pager.setPageno(Integer.parseInt(params.get("pageno").toString()));
        pager.setPagesize(Integer.parseInt(params.get("pagesize").toString()));
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer cout =  pactGmioService.getTenHousListCount(params);
        System.out.println("cout"+cout);
        if(cout == 0){
            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(),params,cout);
        }else {
            List<Map<String, Object>> getTenHousList = pactGmioService.getTenHousList(params);
            for (Map<String,Object> map1:getTenHousList){
                JsonResult tenresult1 =  zwxTenantFeign.getTenId(map1);
                Map<String,Object> tenMap1 =  (Map<String, Object>) tenresult1.get("result");
                map1.putAll(tenMap1);
            }

            return pageUtils.getJsonResult(getTenHousList,params,cout);
        }

    }
}
